/*
 * @(#)PdfTextExtractor.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.dms.extractor;

import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.lucene.extractor.DocumentHandler;

//import com.snowtide.pdf.PDFTextStream;
//import com.snowtide.pdf.Page;
//import com.snowtide.pdf.*;

/**
  PdfTextExtractor.java

  This class is the text extractor for PDF files.

    @author          Rollo Chan
    @company         DCIVision Limited
    @creation date   26/08/2003
    @version         $Revision: 1.15.2.2 $
*/

public class PdfTextExtractor extends AbstractTextExtractor {

  public static final String REVISION = "$Revision: 1.15.2.2 $";
  
  private static final Log log = LogFactory.getLog(PdfTextExtractor.class);
  
  public PdfTextExtractor(InputStream fis, String encoding) throws ApplicationException {
    super(fis, encoding);
    if (fis==null) {
      return;
    }
    
    try {
      String pdfExtractor = SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_INDEX_EXTRACTOR_PDF);
      if (pdfExtractor==null || pdfExtractor.equals("") || pdfExtractor.equals("null")) {
        pdfExtractor = "com.dcivision.lucene.extractor.PDFBoxPDFHandler";
      }
      DocumentHandler handler =  (DocumentHandler)Class.forName(pdfExtractor).newInstance();
      this.text = handler.getDocumentFullText(fis);
    }catch (Exception ex) {
      log.error(ex, ex);
      throw new ApplicationException(ex);
    }
  }
}
